//
//  MyAddressCell.m
//  FD
//
//  Created by Yasin on 2018/10/17.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "MyAddressCell.h"
@interface MyAddressCell()
/**减号按钮*/
@property (nonatomic,  strong) UIButton *deleteBtn;
/**编辑*/
@property (nonatomic,  strong) UIButton *editBtn;
@end

@implementation MyAddressCell
//!!!!:init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}
- (void)setupView
{
    [self.contentView addSubview:self.deleteBtn];
    [self.contentView addSubview:self.nameLb];
    [self.contentView addSubview:self.addressLb];
    [self.contentView addSubview:self.editBtn];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.left.equalTo(self.contentView.mas_left).offset(20);
    }];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(5);
        make.left.equalTo(self.deleteBtn.mas_right).offset(5);
        make.height.mas_equalTo(21);
        make.right.equalTo(self.editBtn.mas_left).offset(-5);
    }];
    
    [self.addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLb.mas_bottom).offset(5);
        make.left.equalTo(self.nameLb.mas_left);
        make.height.mas_equalTo(21);
        make.right.equalTo(self.editBtn.mas_left).offset(-5);
    }];
    
    [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
}


//getter
- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.font = [UIFont systemFontOfSize:16.0f * kScaleFit];
    }
    return _nameLb;
}
- (UILabel *)addressLb {
    if (!_addressLb) {
        _addressLb = [UILabel new];
        _addressLb.font = [UIFont systemFontOfSize:16.0f * kScaleFit];
        _addressLb.textColor = kLightGrayTextColor;
    }
    return _addressLb;
}
- (UIButton *)deleteBtn {
    if (!_deleteBtn) {
        _deleteBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_deleteBtn setImage:[UIImage imageNamed:@"减"] forState:(UIControlStateNormal)];
        [_deleteBtn addTarget:self action:@selector(clickDeleteBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _deleteBtn;
}

- (UIButton *)editBtn {
    if (!_editBtn) {
        _editBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_editBtn setImage:[UIImage imageNamed:@"edit"] forState:(UIControlStateNormal)];
        [_editBtn addTarget:self action:@selector(clickEditBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _editBtn;
}

//!!!!:点击事件
- (void)clickDeleteBtnAction:(UIButton *)btn {
    RBFunctionLog
    if ([self.delegate respondsToSelector:@selector(addressCellClickDeleteAction:)]) {
        [self.delegate addressCellClickDeleteAction:self];
    }
}

- (void)clickEditBtnAction:(UIButton *)btn {
    RBFunctionLog
    if ([self.delegate respondsToSelector:@selector(addressCellClickEditAction:)]) {
        [self.delegate addressCellClickEditAction:self];
    }
}

#pragma mark - 设置数据
- (void)setModel:(MyAddressModel *)model {
    _model = model;
    

    
    NSString *manStr = NSLocalizedString(Home_Man, @"先生");
    NSString *womanStr = NSLocalizedString(Home_Woman, @"女士");
    NSString *sex = manStr;
    if ([model.sex isEqualToNumber:@1]) {
        sex = womanStr;
    }
    
    //1-19将错就错
    self.addressLb.text = [NSString stringWithFormat:@"%@ %@ %@",model.consignee,sex,model.phone];
    self.nameLb.text =     [NSString stringWithFormat:@"%@",model.detail]; //不要Region
    
}
@end
